package com.xzy.bean;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * 使用@ConditionalOnProperty注解实现条件化加载Bean
 * <br>该注解可以基于配置属性的值来决定是否加载Bean。你可以指定一个或多个配置属性名称，并通过设置预期的属性值来触发Bean的加载
 *
 * @author xzy.xiao
 * @date 2023/6/1  14:28
 */
@ConditionalOnProperty(name = "bean.PropertyConditionalBean.enabled", havingValue = "true")
@Slf4j
@Component
public class PropertyConditionalBean {
    @PostConstruct
    public void loadInfo() {
        log.info("条件化加载Bean：PropertyConditionalBean");
    }
}

